package com.room.search.web.rest;

import com.room.search.core.page.TableDataInfo;
import com.room.search.response.RoomResult;
import com.room.search.service.RoomGoodsService;
import com.room.search.service.RoomSearchGoodService;
import com.room.search.service.dto.*;
import org.springframework.web.bind.annotation.*;

/**
 * REST controller for managing {@link com.room.search.domain.RoomGoods}.
 */
@RestController
@RequestMapping("/api/room")
public class RoomGoodsResource {

    private final RoomGoodsService roomGoodsService;
    private final RoomSearchGoodService roomSearchGoodService;

    public RoomGoodsResource(RoomGoodsService roomGoodsService, RoomSearchGoodService roomSearchGoodService) {
        this.roomGoodsService = roomGoodsService;
        this.roomSearchGoodService = roomSearchGoodService;
    }


    /**
     * 根据省份和城市获取推荐房源信息
     */
    @GetMapping("/getAll")
    public RoomResult getAll(GetAllByProvinceAndCityDTO dto) {
        return roomGoodsService.getAll(dto);
    }

    /**
     * 获取所有的房屋列表
     */
    @GetMapping("/goods_list")
    public TableDataInfo getAllRoom(RoomGoodsDTO dto) {
        return roomGoodsService.getAllRoom(dto);
    }


    /**
     * 添加房屋
     */
    @PostMapping("/goods_add")
    public RoomResult addRoomGoods(@RequestBody AddRoomGoodsDTO dto) {
        return roomGoodsService.addRoomGoods(dto);
    }


    /**
     * 修改房产
     */
    @PutMapping("/goods_edit/{id}")
    public RoomResult editRoomGoods(@PathVariable Long id) {
        return null;
    }

    /**
     * 根据小区找到小区找新房和租房和二手房
     */
    @GetMapping("/{communityId}")
    public RoomResult getRoomByCommunity(@PathVariable Long communityId) {
        return roomGoodsService.getRoomByCommunity(communityId);
    }

    /**
     *
     */
    @GetMapping("/by_district")
    public TableDataInfo getAllRoomByDistrict(CityAndDistrictDTO dto) {
        return roomGoodsService.getAllRoomByDistrict(dto);
    }

    @DeleteMapping("/goods_delete/{id}")
    public RoomResult deleteGoods(@PathVariable Long[] id) {
        return roomGoodsService.deleteGoods(id);
    }

    @PutMapping("/goods_search/update_all")
    public RoomResult deleteAllEsGoods() {
        return roomSearchGoodService.updateAll();
    }

}
